<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          icon="el-icon-refresh"
          size="mini"
          @click="showInfoList"
        ></el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="infos">
      <el-table-column label="主机" prop="host" align="left" width="150" />
      <el-table-column label="告警消息" prop="msg" align="center" />
      <el-table-column label="告警时间" prop="msg" align="center">
        <template slot-scope="scope">{{ ft(scope.row.alarmTime) }}</template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="100"
      >
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="removeHandler(scope.row)"
            >移除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { getAllAlarmInfo, removeAlarmInfo } from "@/api/console";
import { formatDate } from "@/utils/index";
export default {
  name: "alarm",
  data() {
    return {
      loading: false,
      infos: [],
    };
  },
  created() {
    this.showInfoList();
  },
  methods: {
    showInfoList() {
      this.loading = true;
      getAllAlarmInfo()
        .then((res) => {
          this.infos = res.data;
          this.loading = false;
        })
        .catch((msg) => {
          this.loading = false;
        });
    },
    ft(timestamp) {
      return formatDate(timestamp);
    },
    removeHandler(row) {
      removeAlarmInfo(row.type).then((res) => {
        this.msgSuccess("操作成功");
        this.showInfoList();
      });
    },
  },
};
</script>